<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/9
 * Time: 15:35
 */
if (!defined('ACCESS')) {
    exit('Access denied.');
}

class AdminTongji extends Base
{

    private static $table_name = 'tong_ji';
    // 查询字段
    private static $columns = array(
        'id',
        'tongji');

    public static function getTableName()
    {
        return self::$table_name;
    }


    public static function getTongji($id)
    {
        $where = array("id" => $id);
        $db = self::__instance();
        $tongji = $db->get(self::getTableName(), self::$columns, $where);
        if ($tongji) {
            return $tongji;
        }
        return array();
    }


    public static function update($id, $data)
    {
        $where = array("id" => $id);
        $db = self::__instance();
        $res = $db->update(self::getTableName(), $data, $where);
        return $res;
    }


    public static function insert($data)
    {
        if (!$data || !is_array($data)) {
            return false;
        }
        $db = self::__instance();
        $res = $db->insert(self::getTableName(), $data);
        return $res;
    }

    public static function replace($data, $id)
    {
        $db = self::__instance();
        if (!is_array($data)) {
            return false;
        }

        if (isset($data['tongji'])) {
            $s1 = "'" . html_entity_decode($data['tongji']) . "'";
        } else {
            $s1 = "''";
        }


//            $s2 = "'" . $value[1] . "'";
//            $s3 = "'" . $value[2] . "'";
//            $s4 = "'" . $value[3] . "'";
//            $s5 = "'" . $value[4] . "'";
//            $s6 = "'" . $value[5] . "'";
//            $s7 = "'" . $value[6] . "'";
//            $s8 = "'" . $value[7] . "'";

        $value_str_s = '(' . $id . ',' . $s1 . ')';


        $sql = "REPLACE INTO tong_ji (`id`,`tongji`) VALUES " . $value_str_s;

        $rt = $db->exec($sql);
        return $rt;
    }

}